//
//  UIButton+CZAddition.m
//
//  Created by 刘凡 on 16/5/17.
//  Copyright © 2016年 itcast. All rights reserved.
//

#import "UIButton+CZAddition.h"
#import  <objc/runtime.h>

@implementation UIButton (CZAddition)


- (void)setSelectIndexPath:(NSIndexPath *)selectIndexPath {
    objc_setAssociatedObject(self, @selector(selectIndexPath), selectIndexPath, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (NSIndexPath* )selectIndexPath {
    
    return objc_getAssociatedObject(self, @selector(selectIndexPath));
}


+ (instancetype)cz_textButton:(NSString *)title fontSize:(CGFloat)fontSize normalColor:(UIColor *)normalColor highlightedColor:(UIColor *)highlightedColor {
    return [self cz_textButton:title fontSize:fontSize normalColor:normalColor highlightedColor:highlightedColor backgroundImageName:nil];
}

+ (instancetype)cz_textButton:(NSString *)title fontSize:(CGFloat)fontSize normalColor:(UIColor *)normalColor highlightedColor:(UIColor *)highlightedColor backgroundImageName:(NSString *)backgroundImageName {
    
    UIButton *button = [[self alloc] init];
    
    [button setTitle:title forState:UIControlStateNormal];
    
    [button setTitleColor:normalColor forState:UIControlStateNormal];
    [button setTitleColor:highlightedColor forState:UIControlStateHighlighted];
    
    button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    
    if (backgroundImageName != nil) {
        [button setBackgroundImage:[UIImage imageNamed:backgroundImageName] forState:UIControlStateNormal];
    }
    
    [button sizeToFit];
    
    return button;
}

+ (instancetype)cz_imageButton:(NSString *)imageName backgroundImageName:(NSString *)backgroundImageName {
    
    UIButton *button = [[self alloc] init];

    
    [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    if (!kStringIsEmpty(backgroundImageName)) {
        [button setBackgroundImage:[UIImage imageNamed:backgroundImageName] forState:UIControlStateNormal];
    }
    
    [button sizeToFit];
    
    return button;
}

+ (instancetype)cz_textButton:(NSString *)title
                     fontSize:(CGFloat)fontSize
                   titleColor:(UIColor *)titleColor
              backgroundColor:(UIColor* )backgroundColor{
    
    return [UIButton cz_textButton:title
                          fontSize:fontSize
                        titleColor:titleColor
                   backgroundColor:backgroundColor
                      cornerRadius:4.0f];
}

+ (instancetype)cz_textButton:(NSString *)title
                     fontSize:(CGFloat)fontSize
                   titleColor:(UIColor *)titleColor
              backgroundColor:(UIColor* )backgroundColor
                 cornerRadius:(CGFloat)radius{
    
    UIButton *button = [[self alloc] init];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    //    [button setTitleColor:backgroundColor forState:UIControlStateHighlighted];
    [button setBackgroundColor:backgroundColor];
    button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    button.layer.cornerRadius = radius;
    button.layer.masksToBounds = YES;
    
    [button sizeToFit];
    return button;
}

+ (instancetype)cz_textButton:(NSString *)title
                     fontSize:(CGFloat)fontSize
                   titleColor:(UIColor *)titleColor
              backgroundColor:(UIColor* )backgroundColor
                 cornerRadius:(CGFloat)radius
                  borderColor:(UIColor* )borderColor{
    UIButton *button = [[self alloc] init];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    //    [button setTitleColor:backgroundColor forState:UIControlStateHighlighted];
    [button setBackgroundColor:backgroundColor];
    button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    button.layer.cornerRadius = radius;
    button.layer.masksToBounds = YES;
    button.layer.borderWidth = 0.5;
    button.layer.borderColor = borderColor.CGColor;
    [button sizeToFit];
    return button;

}

+ (instancetype)cz_textButton:(NSString *)title
                     fontSize:(CGFloat)fontSize
                   titleColor:(UIColor *)titleColor
                        image:(UIImage* )image
              backgroundColor:(UIColor* )backgroundColor
                 cornerRadius:(CGFloat)radius{
    UIButton *button = [[self alloc] init];
    [button setTitle:title forState:UIControlStateNormal];
    [button setTitleColor:titleColor forState:UIControlStateNormal];
    [button setImage:image forState:UIControlStateNormal];
    [button setBackgroundColor:backgroundColor];
    button.titleLabel.font = [UIFont systemFontOfSize:fontSize];
    button.layer.cornerRadius = radius;
    button.layer.masksToBounds = YES;
    [button sizeToFit];
    
    return button;
}


@end
